#include <SFML/Graphics.hpp>
using namespace sf;

// 窗口
int width = 1024;
int height = 768;

// 实际线条
int roadw = 200;   // 宽
int segL = 200;	   // 长
float camD = 0.84; // 相机深度

// 投影线条
struct Line
{
	float x, y, z; // 世界实际坐标
	float X, Y, W; // 屏幕投影坐标
	float scale;   // 比例

	Line() { x = y = z = 0; } // 初始化
	// 世界坐标转换到屏幕
	void camTf(int camX, int camY, int camZ)
	{
		scale = camD / (z - camZ);
		X = (1 + scale * (x - camX)) * width / 2;
		Y = (1 - scale * (y - camY)) * height / 2;
		W = scale * roadw * width / 2;
	}
};

// 绘制四边形
void drawQuad(RenderWindow &w, Color c, int x1, int y1, int w1, int x2, int y2, int w2)
{
	ConvexShape shape(4); // 多边形(顶点数)
	shape.setFillColor(c);
	// 设置顶点坐标 顺时针
	//  0 1
	// 	3 2
	shape.setPoint(0, Vector2f(x1 - w1, y1));
	shape.setPoint(1, Vector2f(x1 + w1, y1));
	shape.setPoint(2, Vector2f(x2 + w2, y2));
	shape.setPoint(3, Vector2f(x2 - w2, y2));
	w.draw(shape); // 绘制四边形
}

int main()
{
	RenderWindow app(VideoMode(width, height), "Outrun Racing--YzhCat!");
	app.setFramerateLimit(60); // 将帧速率限制为最大固定频率。

	std::vector<Line> lines;
	for (int i = 0; i < 1000; i++)
	{
		Line line;
		line.z = i * segL;



		

		lines.push_back(line);
	}
	int N = lines.size();

	while (app.isOpen())
	{
		Event e;
		while (app.pollEvent(e))
		{
			if (e.type == Event::Closed)
				app.close();
			if (e.type == sf::Event::KeyPressed)
			{
				switch (e.key.code)
				{
				case Keyboard::Escape:
					app.close();
					break;
				default:
					// TODO
					break;
				}
			}
		}
		app.clear();
		drawQuad(app, Color::Yellow, 500, 500, 200, 500, 300, 100);
		app.display();
	}
	return 0;
}
